
<!DOCTYPE HTML>
<html lang="zh-hans" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>API · GitBook</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        
        
        
    
    <link rel="stylesheet" href="../../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-search/search.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="doc.html" />
    
    
    <link rel="prev" href="project.html" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="输入并搜索" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../">
            
                <a href="../">
            
                    
                    概览
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" >
            
                <span>
            
                    
                    快速入门
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.1" data-path="project.html">
            
                <a href="project.html">
            
                    
                    项目结构和初始化
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="1.2.2" data-path="api.html">
            
                <a href="api.html">
            
                    
                    API
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.3" data-path="doc.html">
            
                <a href="doc.html">
            
                    
                    生成 API 文档
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.4" data-path="client.html">
            
                <a href="client.html">
            
                    
                    生成客户端
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.3" >
            
                <span>
            
                    
                    概念
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.3.1" data-path="../concepts/cp.html">
            
                <a href="../concepts/cp.html">
            
                    
                    Consumer && Producer
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.2" data-path="../concepts/operator.html">
            
                <a href="../concepts/operator.html">
            
                    
                    Operator
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.3" data-path="../concepts/filter.html">
            
                <a href="../concepts/filter.html">
            
                    
                    Filter
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.4" data-path="../concepts/prefab.html">
            
                <a href="../concepts/prefab.html">
            
                    
                    Prefab
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.5" data-path="../concepts/modifier.html">
            
                <a href="../concepts/modifier.html">
            
                    
                    Modifier
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.6" data-path="../concepts/middleware.html">
            
                <a href="../concepts/middleware.html">
            
                    
                    Middleware
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.7" data-path="../concepts/context.html">
            
                <a href="../concepts/context.html">
            
                    
                    Context
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.8" data-path="../concepts/source.html">
            
                <a href="../concepts/source.html">
            
                    
                    Parameter Generator
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.9" data-path="../concepts/destination.html">
            
                <a href="../concepts/destination.html">
            
                    
                    Destination Handler
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.10" data-path="../concepts/error.html">
            
                <a href="../concepts/error.html">
            
                    
                    错误包
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.11" data-path="../concepts/method.html">
            
                <a href="../concepts/method.html">
            
                    
                    方法包
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.12" data-path="../concepts/configurer.html">
            
                <a href="../concepts/configurer.html">
            
                    
                    配置器机制
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.13" data-path="../concepts/plugin.html">
            
                <a href="../concepts/plugin.html">
            
                    
                    插件机制
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.14" data-path="../concepts/clients.html">
            
                <a href="../concepts/clients.html">
            
                    
                    多客户端整合
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.4" >
            
                <span>
            
                    
                    插件
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.1" data-path="../plugins/logger.html">
            
                <a href="../plugins/logger.html">
            
                    
                    系统日志插件
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.2" data-path="../plugins/reqlog.html">
            
                <a href="../plugins/reqlog.html">
            
                    
                    请求日志插件
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.3" data-path="../plugins/metrics.html">
            
                <a href="../plugins/metrics.html">
            
                    
                    监控指标插件
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.4" data-path="../plugins/tracing.html">
            
                <a href="../plugins/tracing.html">
            
                    
                    请求追踪插件
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.5" data-path="../plugins/profiling.html">
            
                <a href="../plugins/profiling.html">
            
                    
                    性能分析插件
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.6" data-path="../plugins/version.html">
            
                <a href="../plugins/version.html">
            
                    
                    版本信息插件
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.7" data-path="../plugins/healthcheck.html">
            
                <a href="../plugins/healthcheck.html">
            
                    
                    健康检查插件
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.5" >
            
                <span>
            
                    
                    框架开发者指南
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.5.1" data-path="../topics/start.html">
            
                <a href="../topics/start.html">
            
                    
                    准备工作
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.2" data-path="../topics/log.html">
            
                <a href="../topics/log.html">
            
                    
                    log
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.3" data-path="../topics/errors.html">
            
                <a href="../topics/errors.html">
            
                    
                    errors
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.4" data-path="../topics/definition.html">
            
                <a href="../topics/definition.html">
            
                    
                    definition
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.5" data-path="../topics/method.html">
            
                <a href="../topics/method.html">
            
                    
                    definition/method
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.6" data-path="../topics/converter.html">
            
                <a href="../topics/converter.html">
            
                    
                    operators/converter
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.7" data-path="../topics/validator.html">
            
                <a href="../topics/validator.html">
            
                    
                    operators/validator
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.8" data-path="../topics/router.html">
            
                <a href="../topics/router.html">
            
                    
                    service/router
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.9" data-path="../topics/service.html">
            
                <a href="../topics/service.html">
            
                    
                    service
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.10" data-path="../topics/nirvana.html">
            
                <a href="../topics/nirvana.html">
            
                    
                    nirvana
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.11" data-path="../topics/config.html">
            
                <a href="../topics/config.html">
            
                    
                    config
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.12" data-path="../topics/rest.html">
            
                <a href="../topics/rest.html">
            
                    
                    rest
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.13" data-path="../topics/utils.html">
            
                <a href="../topics/utils.html">
            
                    
                    utils
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.14" data-path="../topics/command.html">
            
                <a href="../topics/command.html">
            
                    
                    cmd/nirvana
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            本书使用 GitBook 发布
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href=".." >API</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <h1 id="api">API</h1>
<h2 id="&#x6982;&#x5FF5;">&#x6982;&#x5FF5;</h2>
<h3 id="nirvana-definition">Nirvana Definition</h3>
<p>&#x5728; Nirvana &#x4E2D;&#xFF0C;&#x6240;&#x6709;&#x7684; API &#x90FD;&#x662F;&#x901A;&#x8FC7; Descriptor &#x548C; Definition &#x8FDB;&#x884C;&#x63CF;&#x8FF0;&#x7684;&#x3002;&#x9996;&#x5148;&#x770B;&#x4E00;&#x4E2A; <code>List Messages</code> &#x7684; API &#x5B9A;&#x4E49;&#xFF1A;</p>
<pre><code class="lang-go"><span class="hljs-comment">// &#x5728;&#x4F7F;&#x7528; nirvana init &#x521B;&#x5EFA;&#x7684;&#x6807;&#x51C6;&#x9879;&#x76EE;&#x7ED3;&#x6784;&#x4E2D;&#xFF0C;&#x8FD9;&#x4E2A;&#x6587;&#x4EF6;&#x4F4D;&#x4E8E; pkg/apis/v1/descriptors/message.go</span>

<span class="hljs-keyword">func</span> init() {
    register([]def.Descriptor{{
        <span class="hljs-comment">// Path &#x5B9A;&#x4E49;&#x4E86; API &#x8DEF;&#x5F84;</span>
        Path:        <span class="hljs-string">&quot;/messages&quot;</span>,
        <span class="hljs-comment">// Definitions &#x6570;&#x7EC4;&#x5305;&#x542B;&#x4E86;&#x8FD9;&#x4E2A;&#x8DEF;&#x5F84;&#x4E0B;&#x7684;&#x6240;&#x6709;&#x5B9A;&#x4E49;&#x3002;</span>
        Definitions: []def.Definition{listMessages},
    },
    }...)
}

<span class="hljs-comment">// listMessages &#x5B9A;&#x4E49;&#x4E86;&#x4E00;&#x4E2A;&#x8FD4;&#x56DE; Message &#x5217;&#x8868;&#x7684; API</span>
<span class="hljs-keyword">var</span> listMessages = def.Definition{
    <span class="hljs-comment">// &#x8FD9;&#x4E2A; API &#x8FD4;&#x56DE;&#x7684;&#x662F;&#x8D44;&#x6E90;&#x6570;&#x7EC4;&#xFF0C;&#x6240;&#x4EE5;&#x4F7F;&#x7528; List &#x65B9;&#x6CD5;&#x3002;</span>
    Method:      def.List,
    <span class="hljs-comment">// Summary &#x662F;&#x4E00;&#x4E2A;&#x77ED;&#x8BED;&#xFF0C;&#x7528;&#x4E8E;&#x63CF;&#x8FF0;&#x8FD9;&#x4E2A; API &#x7684;&#x7528;&#x9014;&#x3002;&#x8FD9;&#x4E2A;&#x77ED;&#x8BED;&#x5728;&#x751F;&#x6210;&#x6587;&#x6863;&#x548C;&#x5BA2;&#x6237;&#x7AEF;&#x7684;&#x65F6;&#x5019;&#x7528;&#x4E8E;&#x533A;&#x5206; API&#x3002;</span>
    <span class="hljs-comment">// &#x8FD9;&#x4E2A;&#x5B57;&#x7B26;&#x4E32;&#x53BB;&#x6389;&#x7A7A;&#x683C;&#x540E;&#x4F1A;&#x4F5C;&#x4E3A;&#x751F;&#x6210;&#x5BA2;&#x6237;&#x7AEF;&#x65F6;&#x7684;&#x51FD;&#x6570;&#x540D;&#xFF0C;&#x56E0;&#x6B64;&#x8BF7;&#x786E;&#x4FDD;&#x8FD9;&#x4E2A;&#x5B57;&#x7B26;&#x4E32;&#x662F;&#x6709;&#x610F;&#x4E49;&#x7684;&#x3002;</span>
    Summary:     <span class="hljs-string">&quot;List Messages&quot;</span>,
    <span class="hljs-comment">// &#x8BE6;&#x7EC6;&#x63CF;&#x8FF0;&#x8FD9;&#x4E2A; API &#x7684;&#x7528;&#x9014;&#x3002;</span>
    Description: <span class="hljs-string">&quot;Query a specified number of messages and returns an array&quot;</span>,
    <span class="hljs-comment">// &#x4E1A;&#x52A1;&#x51FD;&#x6570;</span>
    Function:    message.ListMessages,
    <span class="hljs-comment">// &#x5BF9;&#x5E94;&#x4E1A;&#x52A1;&#x51FD;&#x6570;&#x7684;&#x53C2;&#x6570;&#x4FE1;&#x606F;&#x3002;&#x7528;&#x4E8E;&#x544A;&#x77E5; Nirvana &#x4ECE;&#x8BF7;&#x6C42;&#x7684;&#x90A3;&#x4E00;&#x90E8;&#x5206;&#x53D6;&#x5F97;&#x6570;&#x636E;&#xFF0C;&#x7136;&#x540E;&#x4F20;&#x9012;&#x7ED9;&#x4E1A;&#x52A1;&#x51FD;&#x6570;&#x3002;</span>
    Parameters: []def.Parameter{
        {
            <span class="hljs-comment">// &#x53C2;&#x6570;&#x6765;&#x6E90;</span>
            Source:      def.Query,
            <span class="hljs-comment">// &#x53C2;&#x6570;&#x540D;&#x79F0;&#xFF0C;&#x4F5C;&#x4E3A; key &#x4ECE; Source &#x91CC;&#x53D6;&#x503C;&#x3002;</span>
            <span class="hljs-comment">// &#x4E0E;&#x4E1A;&#x52A1;&#x51FD;&#x6570;&#x7684;&#x53C2;&#x6570;&#x540D;&#x79F0;&#x65E0;&#x5173;&#x3002;</span>
            Name:        <span class="hljs-string">&quot;count&quot;</span>,
            <span class="hljs-comment">// &#x9ED8;&#x8BA4;&#x503C;</span>
            Default:     <span class="hljs-number">10</span>,
            <span class="hljs-comment">// &#x53C2;&#x6570;&#x63CF;&#x8FF0; </span>
            Description: <span class="hljs-string">&quot;Number of messages&quot;</span>,
        },
    },
    <span class="hljs-comment">// &#x5BF9;&#x5E94;&#x4E1A;&#x52A1;&#x51FD;&#x6570;&#x7684;&#x8FD4;&#x56DE;&#x7ED3;&#x679C;&#x3002;&#x7528;&#x4E8E;&#x544A;&#x77E5; Nirvana &#x4E1A;&#x52A1;&#x51FD;&#x6570;&#x8FD4;&#x56DE;&#x7ED3;&#x679C;&#x5982;&#x4F55;&#x653E;&#x5230;&#x8BF7;&#x6C42;&#x7684;&#x54CD;&#x5E94;&#x4E2D;&#x3002;</span>
    Results: def.DataErrorResults(<span class="hljs-string">&quot;A list of messages&quot;</span>),
}
</code></pre>
<p>&#x6839;&#x636E;&#x4E0A;&#x9762;&#x7684; API &#x5B9A;&#x4E49;&#xFF0C;&#x518D;&#x5BF9;&#x5E94;&#x4E1A;&#x52A1;&#x51FD;&#x6570;&#xFF1A;</p>
<pre><code class="lang-go"><span class="hljs-comment">// &#x5728;&#x4F7F;&#x7528; nirvana init &#x521B;&#x5EFA;&#x7684;&#x6807;&#x51C6;&#x9879;&#x76EE;&#x7ED3;&#x6784;&#x4E2D;&#xFF0C;&#x8FD9;&#x4E2A;&#x6587;&#x4EF6;&#x4F4D;&#x4E8E; pkg/message/message.go</span>

<span class="hljs-comment">// Message describes a message entry.</span>
<span class="hljs-keyword">type</span> Message <span class="hljs-keyword">struct</span> {
    ID      <span class="hljs-keyword">int</span>    <span class="hljs-string">`json:&quot;id&quot;`</span>
    Title   <span class="hljs-keyword">string</span> <span class="hljs-string">`json:&quot;title&quot;`</span>
    Content <span class="hljs-keyword">string</span> <span class="hljs-string">`json:&quot;content&quot;`</span>
}

<span class="hljs-comment">// ListMessages returns all messages.</span>
<span class="hljs-keyword">func</span> ListMessages(ctx context.Context, count <span class="hljs-keyword">int</span>) ([]Message, error) {
    messages := <span class="hljs-built_in">make</span>([]Message, count)
    <span class="hljs-keyword">for</span> i := <span class="hljs-number">0</span>; i &lt; count; i++ {
        messages[i].ID = i
        messages[i].Title = fmt.Sprintf(<span class="hljs-string">&quot;Example %d&quot;</span>, i)
        messages[i].Content = fmt.Sprintf(<span class="hljs-string">&quot;Content of example %d&quot;</span>, i)
    }
    <span class="hljs-keyword">return</span> messages, <span class="hljs-literal">nil</span>
}
</code></pre>
<p>&#x53EF;&#x4EE5;&#x770B;&#x5230;&#xFF0C;&#x4E1A;&#x52A1;&#x51FD;&#x6570;&#x65E2;&#x4E0D;&#x5173;&#x5FC3;&#x53C2;&#x6570;&#x7684;&#x6765;&#x6E90;&#x548C;&#x7C7B;&#x578B;&#x8F6C;&#x6362;&#xFF0C;&#x4E5F;&#x4E0D;&#x5173;&#x5FC3;&#x5982;&#x4F55;&#x5C06;&#x8FD4;&#x56DE;&#x503C;&#x5199;&#x5230;&#x54CD;&#x5E94;&#x91CC;&#xFF0C;&#x53EA;&#x662F;&#x6309;&#x7167;&#x4E1A;&#x52A1;&#x9700;&#x6C42;&#x5B9E;&#x73B0;&#x903B;&#x8F91;&#x3002;</p>
<h3 id="definition-method">Definition Method</h3>
<p>&#x5728; Nirvana &#x4E2D;&#xFF0C;&#x6211;&#x4EEC;&#x5EFA;&#x8BAE;&#x6240;&#x6709;&#x7684; API &#x90FD;&#x9075;&#x5B88; RESTful &#x98CE;&#x683C;&#xFF0C;&#x5E76;&#x4E14;&#x5728; URL &#x4E2D;&#x643A;&#x5E26; API &#x7684;&#x7248;&#x672C;&#x53F7;&#x3002;&#x4E0B;&#x8868;&#x4E2D;&#x5C55;&#x793A;&#x4E86; Nirvana &#x4E2D;&#x5B9A;&#x4E49;&#x7684;&#x52A8;&#x4F5C;&#x4EE5;&#x53CA;&#x5BF9;&#x5E94;&#x7684; API &#x5B9A;&#x4E49;&#x3002;</p>
<table>
<thead>
<tr>
<th>Nirvana &#x65B9;&#x6CD5;</th>
<th>HTTP &#x65B9;&#x6CD5;</th>
<th>HTTP &#x6210;&#x529F;&#x72B6;&#x6001;&#x7801;</th>
<th>URL</th>
<th>&#x63CF;&#x8FF0;</th>
</tr>
</thead>
<tbody>
<tr>
<td>List</td>
<td>GET</td>
<td>200</td>
<td>/apis/v1/resources</td>
<td>&#x83B7;&#x53D6;&#x8D44;&#x6E90;&#x5217;&#x8868;</td>
</tr>
<tr>
<td>Get</td>
<td>GET</td>
<td>200</td>
<td>/apis/v1/resources/{resource}</td>
<td>&#x6839;&#x636E;&#x8D44;&#x6E90;&#x552F;&#x4E00; ID/Name &#x83B7;&#x53D6;&#x8D44;&#x6E90;</td>
</tr>
<tr>
<td>Create</td>
<td>POST</td>
<td>201</td>
<td>/apis/v1/resources</td>
<td>&#x521B;&#x5EFA;&#x4E00;&#x4E2A;&#x8D44;&#x6E90;&#xFF08;&#x975E;&#x5E42;&#x7B49;&#xFF09;</td>
</tr>
<tr>
<td>Update</td>
<td>PUT</td>
<td>200</td>
<td>/apis/v1/resources/{resource}</td>
<td>&#x66F4;&#x65B0;&#x4E00;&#x4E2A;&#x8D44;&#x6E90;&#xFF08;&#x5E42;&#x7B49;&#xFF09;</td>
</tr>
<tr>
<td>Patch</td>
<td>PATCH</td>
<td>200</td>
<td>/apis/v1/resources/{resource}</td>
<td>&#x4FEE;&#x6539;&#x4E00;&#x4E2A;&#x8D44;&#x6E90;&#x7684;&#x90E8;&#x5206;&#x5185;&#x5BB9;</td>
</tr>
<tr>
<td>Delete</td>
<td>DELETE</td>
<td>204</td>
<td>/apis/v1/resources/{resource}</td>
<td>&#x5220;&#x9664;&#x4E00;&#x4E2A;&#x8D44;&#x6E90;</td>
</tr>
<tr>
<td>AsyncCreate</td>
<td>POST</td>
<td>202</td>
<td>/apis/v1/resources</td>
<td>&#x5F02;&#x6B65;&#x521B;&#x5EFA;&#x8D44;&#x6E90;</td>
</tr>
<tr>
<td>AsyncUpdate</td>
<td>PUT</td>
<td>202</td>
<td>/apis/v1/resources/{resource}</td>
<td>&#x5F02;&#x6B65;&#x66F4;&#x65B0;&#x8D44;&#x6E90;</td>
</tr>
<tr>
<td>AsyncPatch</td>
<td>PATCH</td>
<td>202</td>
<td>/apis/v1/resources/{resource}</td>
<td>&#x5F02;&#x6B65;&#x4FEE;&#x6539;&#x8D44;&#x6E90;&#x90E8;&#x5206;&#x5185;&#x5BB9;</td>
</tr>
<tr>
<td>AsyncDelete</td>
<td>DELETE</td>
<td>202</td>
<td>/apis/v1/resources/{resource}</td>
<td>&#x5F02;&#x6B65;&#x5220;&#x9664;&#x8D44;&#x6E90;</td>
</tr>
</tbody>
</table>
<p>&#x5BF9;&#x4E8E; Nirvana &#x5F02;&#x6B65;&#x65B9;&#x6CD5;&#xFF0C;&#x53D1;&#x51FA;&#x540E;&#x670D;&#x52A1;&#x7AEF;&#x5E94;&#x5F53;&#x53EA;&#x662F;&#x5C06;&#x8BF7;&#x6C42;&#x52A0;&#x5165;&#x6267;&#x884C;&#x961F;&#x5217;&#xFF0C;&#x7136;&#x540E;&#x7ACB;&#x523B;&#x8FD4;&#x56DE;&#x4E00;&#x4E2A;&#x5173;&#x8054;&#x7684;&#x5BF9;&#x8C61;&#x6216;&#x8005;&#x94FE;&#x63A5;&#xFF0C;&#x4F9B;&#x5BA2;&#x6237;&#x7AEF;&#x540E;&#x7EED;&#x67E5;&#x8BE2;&#x8BF7;&#x6C42;&#x6267;&#x884C;&#x72B6;&#x6001;&#x3002;</p>
<p>&#x6240;&#x6709;&#x7684; Nirvana &#x65B9;&#x6CD5;&#x90FD;&#x662F;&#x8BED;&#x4E49;&#x5C42;&#x9762;&#x7684;&#xFF0C;&#x4E3A;&#x7684;&#x662F;&#x63D0;&#x9AD8; API &#x5B9A;&#x4E49;&#x7684;&#x53EF;&#x8BFB;&#x6027;&#x3002;&#x4E5F;&#x5C31;&#x662F;&#x8BF4; List &#x548C; Get &#x5728;&#x4E00;&#x4E2A; HTTP &#x8BF7;&#x6C42;&#x4E2D;&#x4F7F;&#x7528;&#x7684;&#x90FD;&#x662F; GET&#xFF0C;&#x4E24;&#x8005;&#x6CA1;&#x6709;&#x533A;&#x522B;&#x3002;
&#x4F46;&#x662F;&#x4E3A;&#x4E86;&#x4F7F; API &#x5B9A;&#x4E49;&#x66F4;&#x52A0;&#x660E;&#x786E;&#xFF0C;&#x6211;&#x4EEC;&#x5E94;&#x8BE5;&#x6839;&#x636E;&#x573A;&#x666F;&#x786E;&#x5B9A;&#x4F7F;&#x7528;&#x54EA;&#x4E2A; Nirvana &#x65B9;&#x6CD5;&#x3002;&#x6BD4;&#x5982;&#x67D0;&#x4E2A; API &#x662F;&#x8FD4;&#x56DE;&#x4E00;&#x4E2A;&#x8D44;&#x6E90;&#x5217;&#x8868;&#x7684;&#xFF0C;&#x90A3;&#x4E48; Nirvana &#x65B9;&#x6CD5;&#x5C31;&#x5E94;&#x8BE5;&#x662F; List &#x800C;&#x4E0D;&#x662F; Get&#x3002;</p>
<h3 id="definition-source">Definition Source</h3>
<p>Definition Source &#x7528;&#x4E8E;&#x63CF;&#x8FF0;&#x4E00;&#x4E2A;&#x4E1A;&#x52A1;&#x51FD;&#x6570;&#x7684;&#x53C2;&#x6570;&#x7684;&#x6765;&#x6E90;&#x548C;&#x9ED8;&#x8BA4;&#x503C;&#x3002;</p>
<table>
<thead>
<tr>
<th>&#x53C2;&#x6570;&#x6765;&#x6E90;</th>
<th>&#x540D;&#x79F0;</th>
<th>&#x63CF;&#x8FF0;</th>
</tr>
</thead>
<tbody>
<tr>
<td>Path</td>
<td>&#x6709;</td>
<td>&#x53C2;&#x6570;&#x503C;&#x6765;&#x6E90;&#x4E8E; API Path</td>
</tr>
<tr>
<td>Query</td>
<td>&#x6709;</td>
<td>&#x53C2;&#x6570;&#x503C;&#x6765;&#x6E90;&#x4E8E; URL Query</td>
</tr>
<tr>
<td>Header</td>
<td>&#x6709;</td>
<td>&#x53C2;&#x6570;&#x503C;&#x6765;&#x6E90;&#x4E8E; Request Header</td>
</tr>
<tr>
<td>Form</td>
<td>&#x6709;</td>
<td>&#x53C2;&#x6570;&#x503C;&#x6765;&#x6E90;&#x4E8E; Request Body&#xFF0C;&#x4F46;&#x662F; Content-Type &#x5FC5;&#x987B;&#x662F; application/x-www-form-urlencoded &#x6216; multipart/form-data</td>
</tr>
<tr>
<td>File</td>
<td>&#x6709;</td>
<td>&#x53C2;&#x6570;&#x503C;&#x6765;&#x6E90;&#x4E8E; Request Body&#xFF0C;&#x4F46;&#x662F; Content-Type &#x5FC5;&#x987B;&#x662F; multipart/form-data</td>
</tr>
<tr>
<td>Body</td>
<td>&#x65E0;</td>
<td>&#x53C2;&#x6570;&#x503C;&#x6765;&#x6E90;&#x4E8E; Request Body</td>
</tr>
<tr>
<td>Auto</td>
<td>&#x65E0;</td>
<td>Auto &#x7C7B;&#x578B;&#x5BF9;&#x5E94;&#x7684;&#x53C2;&#x6570;&#x5FC5;&#x987B;&#x662F;&#x4E00;&#x4E2A;&#x7ED3;&#x6784;&#x4F53;&#xFF0C;&#x901A;&#x8FC7;&#x7ED3;&#x6784;&#x4F53;&#x7684; tag &#x5B9A;&#x4E49;&#x6765;&#x786E;&#x5B9A;&#x6BCF;&#x4E2A;&#x5B57;&#x6BB5;&#x7684;&#x6765;&#x6E90;</td>
</tr>
<tr>
<td>Prefab</td>
<td>&#x6709;</td>
<td>&#x53C2;&#x6570;&#x503C;&#x6765;&#x6E90;&#x4E8E;&#x5F53;&#x524D; server &#x5185;&#x90E8;&#xFF0C;&#x6BD4;&#x5982;&#x4E00;&#x4E2A; DB &#x94FE;&#x63A5;</td>
</tr>
</tbody>
</table>
<p>Auto &#x7C7B;&#x578B;&#x7684; tag &#x8303;&#x4F8B;&#x5982;&#x4E0B;&#xFF1A;</p>
<pre><code class="lang-go"><span class="hljs-keyword">type</span> Example <span class="hljs-keyword">struct</span> {
    Start       <span class="hljs-keyword">int</span>    <span class="hljs-string">`source:&quot;Query,start,default=100&quot;`</span>
    ContentType <span class="hljs-keyword">string</span> <span class="hljs-string">`source:&quot;Header,Content-Type&quot;`</span>
}
</code></pre>
<p>tag &#x540D;&#x79F0;&#x4E3A; <code>source</code>&#x3002;&#x503C;&#x4F7F;&#x7528;&#x9017;&#x53F7;&#x5206;&#x9694;&#xFF0C;&#x7B2C;&#x4E00;&#x4E2A;&#x53C2;&#x6570;&#x8868;&#x793A;&#x53C2;&#x6570;&#x6765;&#x6E90;&#xFF0C;&#x7B2C;&#x4E8C;&#x4E2A;&#x8868;&#x793A;&#x540D;&#x79F0;&#x3002;&#x5982;&#x679C;&#x662F; Body &#x7C7B;&#x578B;&#x540D;&#x79F0;&#x53EF;&#x4EE5;&#x4E3A;&#x7A7A;&#x3002;
&#x5982;&#x679C;&#x9700;&#x8981;&#x7ED9;&#x5B57;&#x6BB5;&#x8BBE;&#x7F6E;&#x9ED8;&#x8BA4;&#x503C;&#xFF0C;&#x5219;&#x9700;&#x8981;&#x4F7F;&#x7528; <code>default={value}</code> &#x7684;&#x5F62;&#x5F0F;&#x3002; </p>
<p>&#x5982;&#x679C;&#x6709;&#x591A;&#x4E2A; Auto &#x7ED3;&#x6784;&#x4F53;&#xFF0C;&#x53EF;&#x4EE5;&#x7EC4;&#x5408;&#x6210;&#x4E00;&#x4E2A;&#xFF1A;</p>
<pre><code class="lang-go"><span class="hljs-keyword">type</span> AnotherAutoStruct <span class="hljs-keyword">struct</span> {
    ...
}

<span class="hljs-keyword">type</span> Example <span class="hljs-keyword">struct</span> {
    Start       <span class="hljs-keyword">int</span>    <span class="hljs-string">`source:&quot;Query,start,default=100&quot;`</span>
    ContentType <span class="hljs-keyword">string</span> <span class="hljs-string">`source:&quot;Header,Content-Type&quot;`</span>
    AnotherAutoStruct
}
</code></pre>
<p>&#x5BF9;&#x4E8E;&#x6CA1;&#x6709; <code>source</code> &#x7684;&#x7ED3;&#x6784;&#x4F53;&#x7C7B;&#x578B;&#xFF0C;&#x4F1A;&#x9012;&#x5F52;&#x904D;&#x5386;&#x4EE5;&#x5BFB;&#x627E;&#x5E26;&#x6709; <code>source</code> &#x7684;&#x5B57;&#x6BB5;&#x3002;&#x5FFD;&#x7565;&#x6240;&#x6709;&#x6CA1;&#x6709; <code>source</code> &#x7684;&#x5B57;&#x6BB5;&#x3002;</p>
<h3 id="definition-destination">Definition Destination</h3>
<p>Definition Destination &#x7528;&#x4E8E;&#x63CF;&#x8FF0;&#x4E00;&#x4E2A;&#x4E1A;&#x52A1;&#x51FD;&#x6570;&#x7684;&#x53C2;&#x6570;&#x7684;&#x6765;&#x6E90;&#x548C;&#x9ED8;&#x8BA4;&#x503C;&#x3002;</p>
<table>
<thead>
<tr>
<th>&#x8FD4;&#x56DE;&#x503C;&#x76EE;&#x6807;</th>
<th>&#x63CF;&#x8FF0;</th>
</tr>
</thead>
<tbody>
<tr>
<td>Meta</td>
<td>&#x8FD9;&#x4E2A;&#x8FD4;&#x56DE;&#x503C;&#x7C7B;&#x578B;&#x5FC5;&#x987B;&#x662F; map[string]string&#xFF0C;&#x4F1A;&#x5199;&#x5165; Response Header</td>
</tr>
<tr>
<td>Data</td>
<td>&#x8FD4;&#x56DE;&#x503C;&#x53EF;&#x4EE5;&#x662F;&#x4EFB;&#x610F;&#x7ED3;&#x6784;&#xFF0C;&#x81EA;&#x52A8;&#x8F6C;&#x6362;&#x5E76;&#x5199;&#x5165;&#x5230; Response Body</td>
</tr>
<tr>
<td>Error</td>
<td>&#x9519;&#x8BEF;&#x7C7B;&#x578B;&#xFF0C;&#x5FC5;&#x987B;&#x662F; error</td>
</tr>
</tbody>
</table>
<h2 id="&#x7ED9;&#x9879;&#x76EE;&#x6DFB;&#x52A0;&#x4E00;&#x4E2A;-api">&#x7ED9;&#x9879;&#x76EE;&#x6DFB;&#x52A0;&#x4E00;&#x4E2A; API</h2>
<p>&#x63A5;&#x4E0B;&#x6765;&#x6211;&#x4EEC;&#x7ED9;&#x9879;&#x76EE;&#x589E;&#x52A0;&#x4E00;&#x4E2A; API&#xFF0C;&#x7528;&#x4E8E;&#x83B7;&#x53D6;&#x4E00;&#x6761;&#x6D88;&#x606F;&#xFF1A;</p>
<pre><code class="lang-go"><span class="hljs-keyword">func</span> init() {
    register([]def.Descriptor{{
        Path:        <span class="hljs-string">&quot;/messages&quot;</span>,
        Definitions: []def.Definition{listMessages},
    }, {
        <span class="hljs-comment">// &#x83B7;&#x53D6;&#x4E00;&#x6761;&#x6D88;&#x606F;&#x7684; Descriptor&#x3002;</span>
        Path:        <span class="hljs-string">&quot;/messages/{message}&quot;</span>,
        Definitions: []def.Definition{getMessage},
    },
    }...)
}

<span class="hljs-comment">// &#x83B7;&#x53D6;&#x4E00;&#x6761;&#x6D88;&#x606F;&#x7684; API &#x5B9A;&#x4E49;&#x3002;</span>
<span class="hljs-keyword">var</span> getMessage = def.Definition{
    <span class="hljs-comment">// &#x56E0;&#x4E3A;&#x53EA;&#x83B7;&#x53D6;&#x4E00;&#x6761;&#x6D88;&#x606F;&#xFF0C;&#x6B64;&#x5904;&#x4E3A; Get&#x3002;</span>
    Method:      def.Get,
    Summary:     <span class="hljs-string">&quot;Get Message&quot;</span>,
    Description: <span class="hljs-string">&quot;Get a message by id&quot;</span>,
    <span class="hljs-comment">// &#x4E1A;&#x52A1;&#x51FD;&#x6570;</span>
    Function:    message.GetMessage,
    Parameters: []def.Parameter{
        <span class="hljs-comment">// &#x8FD9;&#x662F;&#x4E00;&#x4E2A;&#x5DE5;&#x5177;&#x65B9;&#x6CD5;&#xFF0C;&#x7528;&#x4E8E;&#x5FEB;&#x901F;&#x751F;&#x6210;&#x4E00;&#x4E2A;&#x53C2;&#x6570;&#x7ED3;&#x6784;&#x3002;</span>
        <span class="hljs-comment">// message &#x662F;&#x4ECE; API Path &#x91CC;&#x83B7;&#x53D6;&#x7684;&#x3002;</span>
        def.PathParameterFor(<span class="hljs-string">&quot;message&quot;</span>, <span class="hljs-string">&quot;Message id&quot;</span>),
    },
    Results: def.DataErrorResults(<span class="hljs-string">&quot;A message&quot;</span>),
}
</code></pre>
<p>&#x5BF9;&#x5E94;&#x7684;&#x4E1A;&#x52A1;&#x51FD;&#x6570;&#x5982;&#x4E0B;&#xFF1A;</p>
<pre><code class="lang-go"><span class="hljs-comment">// GetMessage return a message by id.</span>
<span class="hljs-keyword">func</span> GetMessage(ctx context.Context, id <span class="hljs-keyword">int</span>) (*Message, error) {
    <span class="hljs-keyword">return</span> &amp;Message{
        ID:      id,
        Title:   <span class="hljs-string">&quot;This is an example&quot;</span>,
        Content: <span class="hljs-string">&quot;Example content&quot;</span>,
    }, <span class="hljs-literal">nil</span>
}
</code></pre>
<p>&#x6DFB;&#x52A0; API &#x4E4B;&#x540E;&#xFF0C;&#x7F16;&#x8BD1;&#x8FD0;&#x884C;&#x3002;&#x7136;&#x540E;&#x8BBF;&#x95EE; <code>http://localhost:8080/apis/v1/messages/100</code>&#xFF0C;&#x5373;&#x53EF;&#x83B7;&#x5F97;&#x7ED3;&#x679C;&#xFF08;&#x9ED8;&#x8BA4;&#x60C5;&#x51B5;&#x4E0B;&#x90FD;&#x662F; json &#x7C7B;&#x578B;&#xFF09;&#xFF1A;</p>
<pre><code>{&quot;id&quot;:100,&quot;title&quot;:&quot;This is an example&quot;,&quot;content&quot;:&quot;Example content&quot;}
</code></pre><p>&#x8FD9;&#x91CC;&#x6DFB;&#x52A0;&#x7684;&#x4E1A;&#x52A1;&#x51FD;&#x6570;&#x90FD;&#x662F;&#x4EE5; Golang &#x51FD;&#x6570;&#x7684;&#x65B9;&#x5F0F;&#x5448;&#x73B0;&#x7684;&#x3002;&#x5982;&#x679C;&#x5E0C;&#x671B;&#x4F7F;&#x7528;&#x5B9E;&#x4F8B;&#x65B9;&#x6CD5;&#x4F5C;&#x4E3A;&#x4E1A;&#x52A1;&#x7684;&#x5904;&#x7406;&#x51FD;&#x6570;&#xFF0C;&#x8BF7;&#x53C2;&#x8003; <a href="../concepts/method.html">&#x65B9;&#x6CD5;&#x5305;</a>&#x3002;</p>

                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="project.html" class="navigation navigation-prev " aria-label="Previous page: 项目结构和初始化">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="doc.html" class="navigation navigation-next " aria-label="Next page: 生成 API 文档">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"API","level":"1.2.2","depth":2,"next":{"title":"生成 API 文档","level":"1.2.3","depth":2,"path":"guides/doc.md","ref":"guides/doc.md","articles":[]},"previous":{"title":"项目结构和初始化","level":"1.2.1","depth":2,"path":"guides/project.md","ref":"guides/project.md","articles":[]},"dir":"ltr"},"config":{"plugins":[],"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"highlight":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"theme":"default","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"language":"zh-hans","gitbook":"*"},"file":{"path":"guides/api.md","mtime":"2019-08-06T09:48:58.000Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2020-10-20T10:33:16.586Z"},"basePath":"..","book":{"language":"zh-hans"}});
        });
    </script>
</div>

        
    <script src="../../gitbook/gitbook.js"></script>
    <script src="../../gitbook/theme.js"></script>
    
        
        <script src="../../gitbook/gitbook-plugin-search/search-engine.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-search/search.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

